home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / opt0.4.lcm / local / bin / makeconfig < prev    next >
Encoding:
Text File  |  2004-02-26  |  10.2 KB  |  390 lines

  1. #!/bin/sh
  2. # ************************************************************************
  3. # *                                                                      *
  4. # *      makeconfig v0.8 - ECI Linux driver configuration script         *
  5. # *                        by FlashCode and Crevetor (c) 14/04/2002      *
  6. # *                                                                      *
  7. # *          For any support, contact one of us :                        *
  8. # *           - FlashCode: flashcode@flashtux.org                        *
  9. # *                        http://eciadsl.flashtux.org                   *
  10. # *           - Crevetor : ziva@caramail.com                             *
  11. # *                                                                      *
  12. # *      Parameters for this script :                                    *
  13. # *        1  = mode                                                     *
  14. # *        2  = username + domain (username@domain)                      *
  15. # *        3  = password (given by provider)                             *
  16. # *        4  = path to pppoeci (eg: /usr/local/bin/pppoeci)             *
  17. # *        5  = DNS 1 (depends on provider, 0 or "" = skipped)           *
  18. # *        6  = DNS 2 (depends on provider, 0 or "" = skipped)           *
  19. # *        7  = VPI (depends on provider)                                *
  20. # *        8  = VCI (depends on provider)                                *
  21. # *        9  = VID/PID before synchro (example: 05472131 for ECI modem) *
  22. # *        10 = VID/PID after synchro  (example: 09158000 for ECI modem) *
  23. # *        11 = path to a synch .bin                                     *
  24. # *        12 = path to a firmware .bin                                  *
  25. # *        13 = static IP                                                *
  26. # *        14 = gateway IP                                               *
  27. # *        15 = use static IP (yes/no)                                   *
  28. # *        16 = use DHCP (yes/no)                                        *
  29. # *        17 = modem                                                    *
  30. # *        18 = provider                                                 *
  31. # *                                                                      *
  32. # ************************************************************************
  33.  
  34. function backup()
  35. {
  36.     if [ -f "$1" ]
  37.     then
  38.         backupfile="$1.bak"
  39.         num=0
  40.         while [ -s "$backupfile" ]
  41.         do
  42.             num=`expr $num + 1`
  43.             backupfile="$1.bak$num"
  44.         done
  45.         echo -n "backing up $1 to $backupfile.. "
  46.         cp -f "$1" "$backupfile"
  47.         test $? -ne 0 && exit 255
  48.         echo "OK"
  49.     fi
  50. }
  51.  
  52. function set_synch()
  53. {
  54.     if [ -z "$1" ]
  55.     then
  56.         echo "ERROR: missing synch .bin file (use --synch /path/filename)"
  57.         exit 1
  58.     fi
  59.     if [ "${1:0:1}" != "/" ]
  60.     then
  61.         echo "ERROR: illegal synch .bin path/name"
  62.         echo "you must use an absolute path name (for instance: /etc/eciadsl/synchXX.bin)"
  63.         exit 1
  64.     fi
  65.     if [ ! -s "$1" -o -L "$1" ]
  66.     then
  67.         echo "ERROR: $1 is not a valid synch .bin (must be a regular file)"
  68.         exit 1
  69.     fi
  70.     if [ ! -f "$conffile" ]
  71.     then
  72.         echo "ERROR: couldn't find config file $conffile"
  73.         exit 1
  74.     fi
  75.     backup "$conffile"
  76.     tmpconffile="/tmp/eciadsl.conf.tmp"
  77.     TMP=$(echo "$1" | sed "s/\//\\\\\//g")
  78.     sed "s/^[ \t]*SYNCH[ \t]*=.*/SYNCH=$TMP/g" "$conffile" >> "$tmpconffile"
  79.     if [ -s "$tmpconffile" ]
  80.     then
  81.         mv -f "$tmpconffile" "$conffile"
  82.     else
  83.         rm -f "$tmpconffile"
  84.         echo "SYNCH=$2" >> "$conffile"
  85.     fi
  86.     echo "OK"
  87. }
  88.  
  89. function update_entry()
  90. {
  91.     grep -E "^[ \t]*$1[ \t]*=.*" "$backupfile" > /dev/null
  92.     if [ $? -eq 0 ]
  93.     then
  94.         echo "s/^[ \t]*$1[ \t]*=.*/$1=$2/g" >> "$tmpupdatefile"
  95.     else
  96.         echo "$1=$2" >> "$tmpaddfile"
  97.     fi
  98. }
  99.  
  100.  
  101. # <CONFIG>
  102. BIN_DIR="/usr/local/bin"
  103. ETC_DIR="/etc"
  104. CONF_DIR="/etc/eciadsl"
  105. PPPD_DIR="/etc/ppp"
  106. VERSION=""
  107. # </CONFIG>
  108.  
  109. TMPFILE="/tmp/${0##*/}.tmp"
  110. conffile="$CONF_DIR/eciadsl.conf"
  111. case "$1" in
  112. "--version"|"-v")    echo "$VERSION"
  113.                     exit 0
  114.                     ;;
  115. "--synch")            set_synch "$2"
  116.                     exit 0
  117.                     ;;
  118. esac
  119.  
  120. #
  121. # check parameters
  122. #
  123.  
  124. if [ $UID -ne 0 ]
  125. then
  126.     echo -e "\nERROR: you must be root in order to run this script"
  127.     exit 255
  128. fi
  129.  
  130. if [ $# -ne 18 ]
  131. then
  132.     echo -e "\nERROR: invalid number of parameters"
  133.     echo -e "syntax:\n  makeconfig <mode> <username> <password> </path/to/pppoeci> <dns1> <dns2> <vpi> <vci>  <vidpid1> <vidpid2> </path/to/synch.bin> </path/to/firmware.bin> <staticip> <gateway> <use_staticip> <use_dhcp> <modem> <provider>"
  134.     exit 1
  135. fi
  136.  
  137. mode="$1"
  138. username="$2"
  139. password="$3"
  140. pppoeci="$4"
  141. dns1="$5"
  142. dns2="$6"
  143. vpi="$7"
  144. vci="$8"
  145. vid1=`echo $9 | cut -c 1-4`
  146. pid1=`echo $9 | cut -c 5-8`
  147. vid2=`echo ${10} | cut -c 1-4`
  148. pid2=`echo ${10} | cut -c 5-8`
  149. synch="${11}"
  150. firmware="${12}"
  151. staticip=${13}
  152. gateway=${14}
  153. use_staticip=${15}
  154. use_dhcp=${16}
  155. modem="${17}"
  156. provider="${18}"
  157. test -z "$mode" && mode="$($pppoeci --modes 2>&1 | grep default |cut -d ' ' -f 1)"
  158. test -z "$synch" && synch="$CONF_DIR/synch01.bin"
  159. test -z "$firmware" && firmware="$CONF_DIR/firmware00.bin"
  160. test -z "$modem" && modem="Other"
  161. test -z "$provider" && provider="Other"
  162. test -z "$use_staticip" && use_staticip="no"
  163. test -z "$use_dhcp" && use_dhcp="no"
  164.  
  165.  
  166. #
  167. # check/create directories
  168. #
  169.  
  170. test -d "$CONF_DIR" || mkdir -p "$CONF_DIR"
  171. test -d "$PPPD_DIR" || mkdir -p "$PPPD_DIR"
  172. test -d "$PPPD_DIR/peers" || mkdir "$PPPD_DIR/peers"
  173.  
  174.  
  175. if [ ! -f "$pppoeci" -o ! -x "$pppoeci" ]
  176. then
  177.     echo "ERROR: $pppoeci is not a valid executable"
  178.     exit 1
  179. fi
  180. if [ $vpi -ge 4096 ]; then
  181.     echo -e "ERROR: VPI not in range [0-4095]"
  182.     exit 1
  183. fi
  184. if [ $vci -ge 65536 ]; then
  185.     echo -e "ERROR: VCI not in range [0-65535]"
  186.     exit 1
  187. fi
  188.  
  189. RET=0
  190.  
  191. #
  192. # backup and create resolv.conf
  193. #
  194.  
  195. resolvconf="$ETC_DIR/resolv.conf"
  196. if [ -n "$dns1$dns2" -a "$dns1$dns2" != "00" ]
  197. then
  198.     backup "$resolvconf"
  199.  
  200.     echo -n "creating $resolvconf.."
  201.     :> "$resolvconf"
  202.     if [ "$dns1" != "0" -a -n "$dns1" ]
  203.     then
  204.         echo "nameserver $dns1" >> "$resolvconf"
  205.     fi
  206.     if [ "$dns2" != "0" -a -n "$dns2" ]
  207.     then
  208.         echo "nameserver $dns2" >> "$resolvconf"
  209.     fi
  210.     echo "OK"
  211. fi
  212.  
  213. #
  214. # create or backup/modify "chap-secrets" and "pap-secrets"
  215. #
  216.  
  217. for auth in "chap" "pap"
  218. do
  219.     secretfile="$PPPD_DIR/$auth-secrets"
  220.     if [ -s $secretfile ]
  221.     then
  222.         backup "$secretfile"
  223.  
  224.         echo -n "modifying $secretfile.. "
  225.         TMP=$(echo "$username" | sed "s/\\\/\\\\\\\\\\\/g")
  226.         grep -v -E "^[ \t]*\"?$TMP\"?[ \t]*.*\n?" $backupfile > "$secretfile"
  227.     else
  228.         echo -n "creating $secretfile.. "
  229.         echo "# Secrets for authentication using $auth" > "$secretfile"
  230.     fi
  231.     echo -e "\"$username\"\t*\t\"$password\"\t*" >> "$secretfile"
  232.     echo "OK"
  233. done
  234.  
  235. #
  236. # create or backup/modify "adsl" script
  237. #
  238.  
  239. pppdconffile="$PPPD_DIR/peers/adsl"
  240. tmppppdconffile="/tmp/adsl.tmp"
  241. if [ -s $pppdconffile ]
  242. then
  243.     backup "$pppdconffile"
  244.  
  245.     echo -n "modifying $pppdconffile.. "
  246.     TMP=$(echo "$pppoeci" | sed "s/\//\\\\\//g")
  247.     echo "s/^pty .\+/pty \\\"$TMP -vpi $vpi -vci $vci -vendor 0x$vid2 -product 0x$pid2 -mode $mode\\\"/" > $TMPFILE
  248.     TMP=$(echo "$username" | sed "s/\//\\\\\//g")
  249.     echo "s/^user .\+/user \\\"$TMP\\\"/" >> $TMPFILE
  250.     sed -f $TMPFILE "$backupfile" > "$tmppppdconffile"
  251.  
  252.     if [ -s "$tmppppdconffile" ]
  253.     then
  254.         echo "OK"
  255.         mv -f "$tmppppdconffile" "$pppdconffile"
  256.     else
  257.         rm -f "$tmppppdconffile"
  258.         echo -e "\nERROR: failed to set up $pppdconffile"
  259.         RET=1
  260.     fi
  261. else
  262.     echo -n "creating $pppdconffile.. "
  263.     cat << EOFADSL > "$pppdconffile"
  264. # this file has been generated by the configuration tool of the ECIADSL driver
  265.  
  266. debug
  267. kdebug 1
  268. noipdefault
  269. defaultroute
  270. pty "$pppoeci -vpi $vpi -vci $vci -vendor 0x$vid2 -product 0x$pid2 -mode $mode"
  271. sync
  272. user "$username"
  273. noaccomp
  274. nopcomp
  275. noccp
  276. novj
  277. holdoff 10
  278.  
  279. # This will store the pid of pppd in the first line of /var/run/ppp-eciadsl.pid
  280. # and the interface created (like ppp0) on the second line.
  281. linkname eciadsl
  282.  
  283. # maxfail is the number of times pppd retries to execute pppoeci after
  284. # an error. If you put 0, pppd retries forever, filling up the process table
  285. # and thus, making the computer unusable.
  286. maxfail 10
  287.  
  288. usepeerdns
  289. noauth
  290.  
  291. # If your PPP peer answer to LCP EchoReq (lcp-echo requests), you can
  292. # use the lcp-echo-failure to detect disconnected links with:
  293. #
  294. # lcp-echo-interval 600
  295. # lcp-echo-failure 10
  296. #
  297. # However, if your PPP peer DOES NOT answer to lcp-echo request, you MUST
  298. # desactivate this feature with the following line
  299. #
  300. lcp-echo-interval 0
  301.  
  302. # You may need the following, but ONLY as a workaround
  303. # mtu 1432
  304.  
  305. persist
  306. EOFADSL
  307.     echo "OK"
  308. fi
  309.  
  310. #
  311. # create eciadsl.conf file
  312. #
  313.  
  314. if [ -s "$conffile" ]
  315. then
  316.  
  317.     backup "$conffile"
  318.  
  319.     echo -n "updating $conffile.."
  320.     tmpconffile="/tmp/eciadsl.conf.tmp"
  321.     tmpupdatefile="/tmp/eciadsl.conf.update"
  322.     tmpaddfile="/tmp/eciadsl.conf.add"
  323.     TMPFIRMWARE=$(echo "$firmware" | sed "s/\//\\\\\//g")
  324.     TMPSYNCH=$(echo "$synch" | sed "s/\//\\\\\//g")
  325.     TMPUSERNAME=$(echo "$username" | sed "s/\//\\\\\//g")
  326.     TMPPASSWD=$(echo "$password" | sed "s/\//\\\\\//g")
  327.     :> "$tmpupdatefile"
  328.     :> "$tmpaddfile"
  329.     update_entry "VID1" "$vid1"
  330.     update_entry "PID1" "$pid1"
  331.     update_entry "VID2" "$vid2"
  332.     update_entry "PID2" "$pid2"
  333.     update_entry "MODE" "$mode"
  334.     update_entry "VPI" "$vpi"
  335.     update_entry "VCI" "$vci"
  336.     update_entry "FIRMWARE" "$TMPFIRMWARE"
  337.     update_entry "SYNCH" "$TMPSYNCH"
  338.     update_entry "PPPD_USER" "$TMPUSERNAME"
  339.     update_entry "PPPD_PASSWD" "$TMPPASSWORD"
  340.     update_entry "USE_DHCP" "$use_dhcp"
  341.     update_entry "USE_STATICIP" "$use_staticip"
  342.     update_entry "STATICIP" "$staticip"
  343.     update_entry "GATEWAY" "$gateway"
  344.     update_entry "MODEM" "$modem"
  345.     update_entry "PROVIDER" "$provider"
  346.     update_entry "DNS1" "$dns1"
  347.     update_entry "DNS2" "$dns2"
  348.     test -s "$tmpupdatefile" && sed -f "$tmpupdatefile" "$backupfile" > "$tmpconffile" \
  349.                             || cp -f "$backupfile" "$tmpconffile"
  350.     test -s "$tmpaddfile" && cat "$tmpaddfile" >> "$tmpconffile"
  351.     if [ -s "$tmpconffile" ]
  352.     then
  353.         mv -f "$tmpconffile" "$conffile"
  354.         echo "OK"
  355.     else
  356.         rm -f "$tmpconffile"
  357.         echo -e "\nERROR: failed to set up $conffile"
  358.         RET=1
  359.     fi
  360.     rm -f "$tmpaddfile"
  361.     rm -f "$tmpupdatefile"
  362. else
  363.     echo -n "creating $conffile.."
  364.     cat << EOFCONF > "$conffile"
  365. VID1=$vid1
  366. PID1=$pid1
  367. VID2=$vid2
  368. PID2=$pid2
  369. MODE=$mode
  370. VCI=$vci
  371. VPI=$vpi
  372. FIRMWARE=$firmware
  373. SYNCH=$synch
  374. PPPD_USER=$username
  375. PPPD_PASSWD=$password
  376. USE_DHCP=$use_dhcp
  377. USE_STATICIP=$use_staticip
  378. STATICIP=$staticip
  379. GATEWAY=$gateway
  380. MODEM=$modem
  381. PROVIDER=$provider
  382. DNS1=$dns1
  383. DNS2=$dns2
  384. EOFCONF
  385.     echo "OK"
  386. fi
  387.  
  388. rm -f "$TMPFILE" > /dev/null 2>&1
  389. exit $RET
  390.